<?php

    namespace App\Models\V1_bak;

    use Illuminate\Database\Eloquent\Model;
    use Illuminate\Support\Facades\DB;

    class Order extends Model
    {
        /**
         * 统计订单数
         *
         * @param $where
         *
         * @return int
         * author: walker
         * Date: 2019/10/24
         * Time: 10:32
         */
        public function countOrder($where)
        {
            return DB::table('orders')
                     ->where($where)
                     ->whereIn('OrderStatus', [4, 5, 6, 7])
                     ->count('OrderId');
        }

        public function getOrderList($where, $pageStart, $pageCount)
        {

            return DB::table('orders as o')
                     ->where($where)
                     ->whereIn('OrderStatus', [4, 5, 6, 7])
                     ->offset($pageStart)
                     ->limit($pageCount)
                     ->get();
        }

        /**
         * 获取订单商品表
         *
         * @param $oid
         *
         * @return array
         * author: walker
         * Date: 2019/10/24
         * Time: 11:18
         */
        public function getOrderGoods($oid)
        {
            $where   = [];
            $where[] = ['OrderId', '=', $oid];
            return DB::table('orders_products_list')
                     ->where($where)
                     ->get();
        }

        public function getOrderLog($oid)
        {
            $where   = [];
            $where[] = ['OrderId', '=', $oid];
            $field   = 'OrderId, UserName, Log, OrderStatus, AccTime';
            return DB::table('orders_log')
                     ->where($where)
                     ->selectRaw($field)
                     ->get();
        }

        /**
         * 获取国家列表
         *
         * @return array
         * author: walker
         * Date: 2019/10/24
         * Time: 11:21
         */
        public function getCountruList()
        {
            $country =  DB::table('country')
                     ->selectRaw('CId,Acronym')
                     ->orderBy('CId', 'asc')
                     ->get()
                     ;
            $countryList = [];
            foreach (toArr($country) as $item) {
                $countryList[$item['CId']] =$item['Acronym'];
            }
            return $countryList;
        }
    }
